%% 
%class scanner 
%unicode 
%byaccj 
%{
	private Parser yyparser; 
	public scanner (java.io.Reader r, Parser yyparser) { 
		this (r); this.yyparser = yyparser; } 
	public int getLine() { return yyline; } 
%} 
 

/*-*
 * PATTERN DEFINITIONS:
 */
letter          = [A-Za-z]
digit           = [0-9]
alphanumeric    = {letter}|{digit}
other_id_char   = [_]
identifier      = {letter}({alphanumeric}|{other_id_char})*
integer			= {digit}*
double          = {integer}\.{integer}
boolean			= true | false
STRING			= \".*\"

comment			= \/\/.*
whitespace      = [ \r\n\t] 


%%
/**
 * LEXICAL RULES:
 */
int				{ return Parser.INT;}
double			{ return Parser.DOUBLE; }
String			{ return Parser.String; }
boolean			{ return Parser.BOOLEAN; }

void			{ return Parser.VOID; }
new				{ return Parser.NEW; }
return		{ return Parser.RETURN; }

if				{ return Parser.IF; }
else			{ return Parser.ELSE; }
for				{ return Parser.FOR; }

while				{ return Parser.WHILE; }

Player			{ return Parser.Player; }
Dice			{ return Parser.Dice; }
Cell			{ return Parser.Cell; }

";"		{ return Parser.SEMI; }
"["		{ return Parser.LBRACK; }
"]"		{ return Parser.RBRACK; }
"("		{ return Parser.LPAREN; }
")"		{ return Parser.RPAREN; }
","		{ return Parser.COMMA;	}
"{"		{ return Parser.LBRACE; }
"}"		{ return Parser.RBRACE; }
"="		{ return Parser.ASSIGN; }
"."		{ return Parser.DOT; }


"!" |
"<" |
">"		{ return (int) yycharat(0); }

"=="	{ return Parser.EQUAL; }
"!="	{ return Parser.NOT_EQ; } 
"<="	{ return Parser.LESS_EQ; } 
">="	{ return Parser.GRT_EQ; }

"&&"	{ return Parser.AND; }
"||"	{ return Parser.OR; }

"++" { return Parser.INC; }
"--" { return Parser.DEC; }

"+" |
"-" |
"*" |
"/"		{ return (int) yycharat(0); }

{boolean}		{ yyparser.yylval = new ParserVal(yytext());
				  return Parser.BOOLEAN_LITERAL; } 

{identifier}    { yyparser.yylval = new ParserVal(yytext());
				  return Parser.ID; } 

{integer}       { yyparser.yylval = new ParserVal(Integer.parseInt(yytext()));
				  return Parser.INT_LITERAL; }
{double}        { yyparser.yylval = new ParserVal(Double.parseDouble(yytext()));
				  return Parser.DOUBLE_LITERAL; }
{STRING}		{ yyparser.yylval = new ParserVal(yytext());
				  return Parser.STRING_LITERAL; }

{comment}       { }
{whitespace}    { }
.               { System.out.println("Illegal char, '" + yytext() +
									 "' line: " + yyline + ", column: " + yychar); }
